home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / MAG09.ZIP / FANGLORE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-15  |  10.8 KB  |  317 lines

  1. { ************************************************************************** }
  2. { *                                                                        * }
  3. { *                                FANGLORE                                * }
  4. { *                                                                        * }
  5. { *                             BY SPELLCASTER                             * }
  6. { *                                                                        * }
  7. { *                              VERSION 0.20                              * }
  8. { *                                                                        * }
  9. { *                            DATE : 20-4-1996                            * }
  10. { *                                                                        * }
  11. { *                                                                        * }
  12. { *  Developed of 'The Mag', Issue 8 for the 'Designing a Text Adventure'  * }
  13. { *  series of articles...                                                 * }
  14. { *                                                                        * }
  15. { ************************************************************************** }
  16.  
  17.  
  18. Program FangLore;
  19.  
  20. { ************************************************************************** }
  21. { ************************** Unit definition ******************************* }
  22. { ************************************************************************** }
  23.  
  24. Uses Crt;    { Use CRT for cute text procedures :) }
  25.  
  26. { ************************************************************************** }
  27. { ************************* Constant definition **************************** }
  28. { ************************************************************************** }
  29.  
  30. Const NumberRooms=22;   { Number of rooms in the game }
  31.  
  32. { ************************************************************************** }
  33. { *************************** Type definition ****************************** }
  34. { ************************************************************************** }
  35.  
  36. Type RoomType=Record
  37.                     Desc:Array[1..10] of String[79];  { Description }
  38.                     North,South,East,West:Byte;       { Exits }
  39.               End;
  40.  
  41.      ParsedType=Array[1..10] Of String;
  42.  
  43. { ************************************************************************** }
  44. { ************************* Variable definition **************************** }
  45. { ************************************************************************** }
  46.  
  47. Var Rooms:Array[1..NumberRooms] of RoomType;   { Room data }
  48.     CurrentRoom:Word;                          { Speaks for itself... :) }
  49.  
  50. { ************************************************************************** }
  51. { ************************ Procedure definition **************************** }
  52. { ************************************************************************** }
  53.  
  54. Function FindSpace(S:String;Start:Byte):Byte;     { Finds the first space    }
  55.                                                   { after the indicated char }
  56. Begin
  57.      While (S[Start+1]<>' ') And (Start<Length(S)) Do Inc(Start);
  58.      FindSpace:=Start;
  59. End;
  60.  
  61. Function GetString(S:String;Start,Finish:Byte):String;    { Gets a piece of }
  62.                                                           { a string        }
  63. Var A:Byte;
  64.     Tmp:String;
  65. Begin
  66.      Tmp:='';
  67.      For A:=Start+1 To Finish Do Tmp:=Tmp+S[A];
  68.      GetString:=Tmp;
  69. End;
  70.  
  71. Function Upper(S:String):String;
  72. Var Tmp:String;
  73.     A:Byte;
  74. Begin
  75.      Tmp:='';
  76.      For A:=1 To Length(S) Do Tmp:=Tmp+UpCase(S[A]);
  77.      Upper:=Tmp;
  78. End;
  79.  
  80. Procedure Parse(S:String;Var Parsed:ParsedType);   { Parses a string }
  81. Var ArrayIndex:Byte;
  82.     StringIndex:Byte;
  83.     NextSpace:Byte;
  84. Begin
  85.      ArrayIndex:=1;
  86.      StringIndex:=0;
  87.      NextSpace:=FindSpace(S,StringIndex);
  88.      While (StringIndex<=Length(S)) And (ArrayIndex<11) Do
  89.      Begin
  90.           NextSpace:=FindSpace(S,StringIndex);
  91.           Parsed[ArrayIndex]:=GetString(S,StringIndex,NextSpace);
  92.           StringIndex:=NextSpace+1;
  93.           Inc(ArrayIndex);
  94.      End;
  95. End;
  96.  
  97. Procedure Elimin(Var Parsed:ParsedType;Var Index:Byte);
  98. Var A:Byte;
  99. Begin
  100.      For A:=Index To 9 Do Parsed[A]:=Parsed[A+1];
  101.      Parsed[10]:='';
  102.      Dec(Index);
  103. End;
  104.  
  105. Procedure EliminPrenoms(Var Parsed:ParsedType);
  106. Var A:Byte;
  107. Begin
  108.      For A:=1 To 10 Do
  109.      Begin
  110.           If Parsed[A]='THE' Then Elimin(Parsed,A);
  111.           If Parsed[A]='A' Then Elimin(Parsed,A);
  112.      End;
  113. End;
  114.  
  115. Procedure ReadRoomData;     { Read from the disk the room data }
  116. Var F:Text;
  117.     A,B:Byte;
  118.     Flag:Boolean;
  119. Begin
  120.      { Prepares the text file for accessing }
  121.      Assign(F,'Room.Dat');
  122.      Reset(F);
  123.      { For every room in the game }
  124.      For A:=1 To NumberRooms Do
  125.      Begin
  126.           { Clear the room's description }
  127.           For B:=1 To 10 Do Rooms[A].Desc[B]:='';
  128.           { Read the description of the room }
  129.           Flag:=True;
  130.           B:=1;
  131.           While Flag Do
  132.           Begin
  133.                Readln(F,Rooms[A].Desc[B]);
  134.                If (B=10) Or (Rooms[A].Desc[B]='*') Then Flag:=False;
  135.                Inc(B);
  136.           End;
  137.           { Read exit data }
  138.           Readln(F,Rooms[A].North);
  139.           Readln(F,Rooms[A].South);
  140.           Readln(F,Rooms[A].East);
  141.           Readln(F,Rooms[A].West);
  142.      End;
  143.      Close(F);
  144. End;
  145.  
  146. Procedure Look(RoomNumber:Word);        { Looks at the room }
  147. Var A:Byte;
  148. Begin
  149.      Writeln;
  150.      A:=1;
  151.      TextColor(White);
  152.      While (A<11) And (Rooms[RoomNumber].Desc[A]<>'*') Do
  153.      Begin
  154.           Writeln(Rooms[RoomNumber].Desc[A]);
  155.           Inc(A);
  156.      End;
  157.      Writeln;
  158.      TextColor(Yellow);
  159.      Writeln('Visible exits:');
  160.      If Rooms[RoomNumber].North<>0 Then Write('North      ');
  161.      If Rooms[RoomNumber].South<>0 Then Write('South      ');
  162.      If Rooms[RoomNumber].East<>0 Then Write('East       ');
  163.      If Rooms[RoomNumber].West<>0 Then Write('West       ');
  164.      Writeln;
  165.      Writeln;
  166. End;
  167.  
  168. Procedure Init;      { Initializes game data }
  169. Begin
  170.      ReadRoomData;
  171.      CurrentRoom:=22;
  172.      TextColor(LightGray);
  173.      TextBackground(Black);
  174.      Clrscr;
  175. End;
  176.  
  177. Procedure Play;      { Playing the game }
  178. Var ExitFlag:Boolean;
  179.     Valid:Boolean;
  180.     Command:String;
  181.     Parsed:ParsedType;
  182.     A:Byte;
  183.     C:Char;
  184. Begin
  185.      ExitFlag:=False;
  186.      Look(CurrentRoom);
  187.      Repeat
  188.            Valid:=False;
  189.            TextColor(White);
  190.            Writeln('What is thy bidding, master ?');
  191.            TextColor(LightGreen);
  192.            Readln(Command);
  193.            { Clear the array }
  194.            For A:=1 To 10 Do Parsed[A]:='';
  195.            Parse(Command,Parsed);
  196.            { Convert to uppercase }
  197.            For A:=1 To 10 Do Parsed[A]:=Upper(Parsed[A]);
  198.            { Eliminate prenoms }
  199.            EliminPrenoms(Parsed);
  200.            { Execute comands }
  201.            If Parsed[1]='LOOK' Then
  202.            Begin
  203.                 Valid:=True;
  204.                 Look(CurrentRoom);
  205.            End;
  206.            If (Parsed[1]='N') Or (Parsed[1]='NORTH') Then
  207.            Begin
  208.                 If Rooms[CurrentRoom].North=0 Then
  209.                 Begin
  210.                      TextColor(LightRed);
  211.                      Writeln;
  212.                      Writeln('Sorry, oh Great Lord, but I can''t go that way !');
  213.                      Writeln;
  214.                 End
  215.                 Else
  216.                 Begin
  217.                      TextColor(LightRed);
  218.                      Writeln;
  219.                      Writeln('You go north...');
  220.                      CurrentRoom:=Rooms[CurrentRoom].North;
  221.                      Writeln;
  222.                      Look(CurrentRoom);
  223.                 End;
  224.                 Valid:=True;
  225.            End;
  226.            If (Parsed[1]='S') Or (Parsed[1]='SOUTH') Then
  227.            Begin
  228.                 If Rooms[CurrentRoom].South=0 Then
  229.                 Begin
  230.                      TextColor(LightRed);
  231.                      Writeln;
  232.                      Writeln('Sorry, oh Great Lord, but I can''t go that way !');
  233.                      Writeln;
  234.                 End
  235.                 Else
  236.                 Begin
  237.                      TextColor(LightRed);
  238.                      Writeln;
  239.                      Writeln('You go south...');
  240.                      CurrentRoom:=Rooms[CurrentRoom].South;
  241.                      Writeln;
  242.                      Look(CurrentRoom);
  243.                 End;
  244.                 Valid:=True;
  245.            End;
  246.            If (Parsed[1]='E') Or (Parsed[1]='EAST') Then
  247.            Begin
  248.                 If Rooms[CurrentRoom].East=0 Then
  249.                 Begin
  250.                      TextColor(LightRed);
  251.                      Writeln;
  252.                      Writeln('Sorry, oh Great Lord, but I can''t go that way !');
  253.                      Writeln;
  254.                 End
  255.                 Else
  256.                 Begin
  257.                      TextColor(LightRed);
  258.                      Writeln;
  259.                      Writeln('You go east...');
  260.                      CurrentRoom:=Rooms[CurrentRoom].East;
  261.                      Writeln;
  262.                      Look(CurrentRoom);
  263.                 End;
  264.                 Valid:=True;
  265.            End;
  266.            If (Parsed[1]='W') Or (Parsed[1]='WEST') Then
  267.            Begin
  268.                 If Rooms[CurrentRoom].West=0 Then
  269.                 Begin
  270.                      TextColor(LightRed);
  271.                      Writeln;
  272.                      Writeln('Sorry, oh Great Lord, but I can''t go that way !');
  273.                      Writeln;
  274.                 End
  275.                 Else
  276.                 Begin
  277.                      TextColor(LightRed);
  278.                      Writeln;
  279.                      Writeln('You go west...');
  280.                      CurrentRoom:=Rooms[CurrentRoom].West;
  281.                      Writeln;
  282.                      Look(CurrentRoom);
  283.                 End;
  284.                 Valid:=True;
  285.            End;
  286.            If Parsed[1]='QUIT' Then
  287.            Begin
  288.                 Valid:=True;
  289.                 TextColor(LightMagenta);
  290.                 Writeln;
  291.                 Writeln('Are you sure you want to quit FangLore (Y/N) ?');
  292.                 C:=ReadKey;
  293.                 If UpCase(C)='Y' Then ExitFlag:=True;
  294.                 Writeln;
  295.            End;
  296.            If Not Valid Then
  297.            Begin
  298.                 Writeln;
  299.                 TextColor(LightRed);
  300.                 If Random(100)>50 Then
  301.                    Writeln('Sorry mylord, by thy bidding can''t be obbeyed...')
  302.                 Else
  303.                    Writeln('What ?! How the hell am I supposed to do that ??');
  304.                 Writeln;
  305.            End;
  306.      Until ExitFlag;
  307. End;
  308.  
  309. { ************************************************************************** }
  310. { **************************** Main  Program ******************************* }
  311. { ************************************************************************** }
  312.  
  313. Begin
  314.      Init;
  315.      Play;
  316. End.
  317.